package com.zxx.order.service.repository

import com.zqq.baselibrary.http.RetrofitFactory
import com.zqq.baselibrary.http.rx.BaseResp
import com.zxx.order.service.api.OrderApi
import com.zxx.order.service.bean.*
import rx.Observable
import javax.inject.Inject

/**
 * 订单数据层
 * wc
 * @author zqq on 2019/6/29.
 */
class OrderRepository @Inject constructor() {

    //根据ID查询订单
    fun getOrderById(orderId: Int): Observable<BaseResp<Order>> {
        return RetrofitFactory.instance
                .create(OrderApi::class.java)
                .getOrderById(GetOrderByIdReq(orderId))
    }


    //根据状态查询订单列表
    fun getOrderList(orderStatus: Int): Observable<BaseResp<MutableList<Order>?>> {
        return RetrofitFactory.instance
                .create(OrderApi::class.java)
                .getOrderList(GetOrderListReq(orderStatus))
    }


    //确认订单
    fun confirmOrder(orderId: Int): Observable<BaseResp<String>> {
        return RetrofitFactory.instance
                .create(OrderApi::class.java)
                .confirmOrder(ConfirmOrderReq(orderId))
    }

    //取消订单
    fun cancelOrder(orderId: Int): Observable<BaseResp<String>> {
        return RetrofitFactory.instance
                .create(OrderApi::class.java)
                .cancelOrder(CancelOrderReq(orderId))
    }

    //提交订单
    fun submitOrder(order: Order): Observable<BaseResp<String>> {
        return RetrofitFactory.instance
                .create(OrderApi::class.java)
                .submitOrder(SubmitOrderReq(order))
    }

}